import { View } from "../../../../mvc/core/View";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { Cache } from "../../../cache/Cache";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { TilePanel } from "../../equipment/TilePanel";
import { GuildSkillPublicCellRenderer } from "./GuildSkillPublicCellRenderer";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GuildSkillPrivateCellRenderer } from "./GuildSkillPrivateCellRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { DataEvent } from "../../../events/DataEvent";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { SkillConfig } from "../../../resource/SkillConfig";
type int = number;
//class GuildSkillPanel
    
    export  class GuildSkillPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            Dispatcher.addEventListener(EventName.GuildSkillStudyTimeUpdate, this.onGuildSkillStudyTimeUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.serverBagDataChangehandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.serverBagDataChangehandler);
            return;
        }

        /* internal  */init(): void
        {
            var loc2=null;
            var loc3=null;
            this._maxStudyTimes = Cache.instance.guild.getMaxSkillStudyTime();
            this._tft = new GTextFormat(FontUtil.songtiName, 14, 15788607, true);
            this._pubSprite = new Object /* flash.display.Sprite */();
            this.addChild(this._pubSprite);
            ObjCreate.createBg(0, 0, 245, 355, this._pubSprite);
            ObjCreate.createBg(0, -1, 247, 28, this._pubSprite, ImagesConst.RbListHeader);
            ObjCreate.createBitmap(ImagesConst.GuildSkillFire, 60, -2, this._pubSprite);
            ObjCreate.createTextField(Language.getString(57554), 95, 7, 200, 20, this._pubSprite, this._tft);
            this._publicSkillList = new TilePanel();
            this._publicSkillList.columnWidth = 215;
            this._publicSkillList.rowHeight = 80;
            this._publicSkillList.setStyle("cellRenderer", GuildSkillPublicCellRenderer);
            this._publicSkillList.setSize(235, 320);
            this._publicSkillList.move(5, 30);
            this._publicSkillList.scrollPolicy = ScrollPolicy.ON;
            this._publicSkillList.drawNow();
            this.addChild(this._publicSkillList);
            this._tipTxt = ObjCreate.createTextField(Language.getString(380001), 0, 180, 245, 20, this._pubSprite, GlobalStyle.textFormat6);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._priSprite = new Object /* flash.display.Sprite */();
            this._priSprite.x = 247;
            this._priSprite.y = 0;
            this.addChild(this._priSprite);
            ObjCreate.createBg(0, 0, 415, 355, this._priSprite);
            ObjCreate.createBg(0, -1, 417, 28, this._priSprite, ImagesConst.RbListHeader);
            ObjCreate.createBitmap(ImagesConst.GuildSkillFire, 135, -2, this._priSprite);
            ObjCreate.createTextField(Language.getString(57555), 160, 7, 200, 20, this._priSprite, this._tft);
            ObjCreate.createTextField(Language.getString(57556), 275, 8, 200, 20, this._priSprite, GlobalStyle.textFormat6);
            this._studyTimesTxt = ObjCreate.createTextField("0/" + this._maxStudyTimes, 360, 8, 200, 20, this._priSprite, GlobalStyle.textFormatGreen);
            this._privateSkillList = new TilePanel();
            this._privateSkillList.styleName = "GScrollPane";
            this._privateSkillList.columnWidth = 190;
            this._privateSkillList.rowHeight = 80;
            this._privateSkillList.verticalGap = 0;
            this._privateSkillList.horizontalGap = 5;
            this._privateSkillList.setStyle("cellRenderer", GuildSkillPrivateCellRenderer);
            this._privateSkillList.setSize(405, 320);
            this._privateSkillList.move(5, 30);
            this._privateSkillList.scrollPolicy = ScrollPolicy.ON;
            this._privateSkillList.drawNow();
            this._priSprite.addChild(this._privateSkillList);
            this._botSprite = new Object /* flash.display.Sprite */();
            this._botSprite.x = 0;
            this._botSprite.y = 355;
            this.addChild(this._botSprite);
            ObjCreate.createBg(0, 0, 665, 45, this._botSprite, ImagesConst.WindowBg2);
            var loc1=15;
            ObjCreate.createTextField(Language.getString(57557), 5, loc1, 200, 20, this._botSprite);
            this._resourceTxt = ObjCreate.createTextField("0", 45, loc1, 200, 20, this._botSprite, GlobalStyle.textFormatOrange);
            ObjCreate.createTextField(Language.getString(57558), 95, loc1, 200, 20, this._botSprite);
            this._contributeTxt = ObjCreate.createTextField("0", 135, loc1, 200, 20, this._botSprite, GlobalStyle.textFormatOrange);
            ObjCreate.createTextField(Language.getString(57559), 180, loc1, 200, 20, this._botSprite);
            this._propAmountTxt = ObjCreate.createTextField("0", 240, loc1, 200, 20, this._botSprite, GlobalStyle.textFormatOrange);
            loc2 = ObjCreate.createTextField("", 255, loc1, 350, 20, this._botSprite);
            loc2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            loc2.htmlText = Language.getString(57560);
            return;
        }

        public updateSkillList(): void
        {
            this._maxStudyTimes = Cache.instance.guild.getMaxSkillStudyTime();
            this._privateSkillArray = Cache.instance.skill.skillGuildMaps;
            this.updatePrivateSkillList(this._privateSkillArray);
            this.onGuildSkillStudyTimeUpdateHandler(null);
            this.updateRes();
            return;
        }

        /* internal  */updatePublicSkillList(arg1: Array<any>): void
        {
            if (!this._publicDataProvider) 
            {
                this._publicDataProvider = new DataProvider();
            }
            this._publicDataProvider.removeAll();
            var loc1=0;
            while (loc1 < arg1.length) 
            {
                this._publicDataProvider.addItem(arg1[loc1]);
                ++loc1;
            }
            this._publicSkillList.dataProvider = this._publicDataProvider;
            return;
        }

        /* internal  */updatePrivateSkillList(arg1: Array<any>): void
        {
            if (!this._privateDataProvider) 
            {
                this._privateDataProvider = new DataProvider();
            }
            this._privateDataProvider.removeAll();
            var loc1=0;
            while (loc1 < arg1.length) 
            {
                this._privateDataProvider.addItem(arg1[loc1]);
                ++loc1;
            }
            this._privateSkillList.dataProvider = this._privateDataProvider;
            return;
        }

        /* internal  */onGuildSkillStudyTimeUpdateHandler(arg1: DataEvent): void
        {
            this._studyTimes = Cache.instance.guild.skillStudyTime;
            this._studyTimesTxt.text = this._studyTimes + "/" + this._maxStudyTimes;
            return;
        }

        /* internal  */updateRes(): void
        {
            this._resourceTxt.text = Cache.instance.guild.myGuildInfo.money.toString();
            this._contributeTxt.text = Cache.instance.guild.myGuildInfo.contribution.toString();
            this._propAmountTxt.text = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropGuildSkillLearn).toString();
            return;
        }

        /* internal  */serverBagDataChangehandler(arg1: Object=null): void
        {
            this._propAmountTxt.text = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropGuildSkillLearn).toString();
            return;
        }

        /* internal  */addTest(): void
        {
            var loc1=[];
            var loc2=0;
            while (loc2 < 6) 
            {
                loc1.push(SkillConfig.instance.getInfoByName(1000616 + loc2));
                ++loc2;
            }
            this.updatePublicSkillList(loc1);
            this.updatePrivateSkillList(loc1);
            return;
        }

        public /* var */isShow: Boolean;

        /* internal */ /* var */_pubSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_priSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_botSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_studyTimesTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_publicSkillList: TilePanel;

        /* internal */ /* var */_privateSkillList: TilePanel;

        /* internal */ /* var */_tft: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_resourceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_contributeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_propAmountTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_studyTimes: int;

        /* internal */ /* var */_maxStudyTimes: int=15;

        /* internal */ /* var */_publicDataProvider: DataProvider;

        /* internal */ /* var */_privateDataProvider: DataProvider;

        /* internal */ /* var */_privateSkillArray: Array<any>;
    }
